﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Ivy.Common.Framework.GeneralUtility;
using Ivy.UserRegistration.IBusinessLogic;
using Ivy.UserRegistration.BusinessLogic;
using Ivy.UserRegistration.Entity;
using HSMPWeb.ViewEntity;
namespace HSMPWeb
{
    public partial class Main2 : System.Web.UI.MasterPage
    {
        #region  Variable& constant
        #endregion  Variable& constant

        #region Constructor & Destructor
        #endregion Constructor & Destructor

        #region Properties
        #endregion Properties

        #region Public Methods
        #endregion Public Methods

        #region Events
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadMenu("");
            }

            if (Session["UserContext"] != null)
            {
                UserContext UserSession = (UserContext)(Session["UserContext"]);
                lblUser.Text = UserSession.CurrentUser.UserFirstName.ToString() + " " + UserSession.CurrentUser.UserLastName.ToString();
                //lblUser.Text = lblUser.Text + "You are currently signed in as member of [" + UserSession.CurrentSociety.SocietyName + "]";
                //lblUser.Text = lblUser.Text + "You current role is [" + UserSession.CurrentRole.RoleName + "]";
                //login.Visible = false;
                //logout.Visible = true;
                Page.RegisterStartupScript("myScript", "<script language=JavaScript>$('#login').hide(); $('#logout').show();</script>");
                //Page.ClientScript.RegisterStartupScript(GetType(this), "myScript", "<script language=JavaScript>$('#login').hide(); $('#logout').show();</script>");
                if (UserSession.CurrentRole != null)
                {
                    LoadMenu(UserSession.CurrentRole.RoleCode);
                    
                }
                else
                {
                    LoadMenu("");

                }
            }
            else
            {
                lblUser.Text = string.Empty;
                //login.Visible = true;
                //logout.Visible = false;
                Page.RegisterStartupScript("myScript", "<script language=JavaScript>$('#login').show(); $('#logout').hide();</script>");
                //Page.ClientScript.RegisterStartupScript("myScript", "<script language=JavaScript>$('#login').show(); $('#logout').hide();</script>");
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    IUserRegistrationBus lUserRegistrationBus = new UserRegistrationBus();

            //    if (lUserRegistrationBus.Login(txtUserName.Text.Trim(), txtPassword.Text.Trim()))
            //    {
            //        User lUser = new User();
            //        lUser = lUserRegistrationBus.GetUserByLoginID(txtUserName.Text.Trim());
            //        UserContext UserSession = new UserContext();
            //        UserSession.UserLoginID = lUser.UserLoginID;
            //        UserSession.UserFirstName = lUser.UserFirstName;
            //        UserSession.UserLastName = lUser.UserLastName;
            //        UserSession.UserPrimaryEmailID = lUser.UserPrimaryEmailID;
            //        UserSession.UserVerificationCode = lUser.UserVerificationCode;
            //        UserSession.UserIsVerified = lUser.UserIsVerified;
            //        Session["UserContext"] = UserSession;
            //        if (lUser.UserIsVerified)
            //        {
            //            //// Response.Redirect("~/Default.aspx");
            //            // lblUser.Text = UserSession.UserLoginID;
            //            // //login.Visible = false;
            //            // //logout.Visible = true;
            //            // Page.RegisterStartupScript("myScript", "<script language=JavaScript>$('#logout').show(); $('#login').hide();</script>");
            //            Response.Redirect(Request.Url.AbsolutePath);
            //        }
            //        else
            //        {
            //            Response.Redirect("~/Pages/UserVerification.aspx");
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    System.Diagnostics.Debug.Print(ex.Message);
            //}
        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Session.Clear();
            lblUser.Text = string.Empty;
            //Page.RegisterStartupScript("myScript", "<script language=JavaScript>$('#login').show(); $('#logout').show();</script>");
            Response.Redirect(Request.Url.AbsolutePath);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtSearch.Text.Trim() != "")
            {
                Response.Redirect("https://www.google.co.in/search?q=" + txtSearch.Text.Trim(), false);
            }
        }

        protected void btnRegister_onclick(object sender, EventArgs e)
        {
            Response.Redirect("~/Pages/UserVerification.aspx");
            //Response.Redirect("~/Pages/Registration.aspx");
        }

        #endregion Events

        #region Private Methods
        private void LoadMenu(string RoleCode)
        {
            switch (RoleCode)
            {
                case "SYSSPRADM":
                    SystemSuperAdminMenu();
                    break;
                case "SYSADMIN":
                    SystemAdminMenu();
                    break;
                case "SYSOPRAT":
                    SystemOpreatorMenu();
                    break;
                case "SCTSUPADM":
                    SocietySuperAdminMenu();
                    break;
                case "SCTADMIN":
                    SocietyAdminMenu();
                    break;
                case "SCTOPRAT":
                    SocietyOpreatorMenu();
                    break;
                case "APTBLDR":
                    BuilderMenu();
                    break;
                case "FLTOWNER":
                    FlatOwnerMenu();
                    break;
                case "FLTRESI":
                    ResidentrMenu();
                    break;
                default:
                    DefaultMenu();
                    break;
            }
            
        }
        private void SystemSuperAdminMenu()
        {
            smoothmenu1.Items.Clear();
            smoothmenu1.Items.Add(new MenuItem("Home", "", "", "~/HsmpHomePage1.aspx"));
            MenuItem mItemsPortalAdmin = new MenuItem("Portal Admin", "", "", "");
            mItemsPortalAdmin.ChildItems.Add(new MenuItem("Reports", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            mItemsPortalAdmin.ChildItems.Add(new MenuItem("Publish Notice", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            mItemsPortalAdmin.ChildItems.Add(new MenuItem("Add System Admin", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(mItemsPortalAdmin);
            
            smoothmenu1.Items.Add(new MenuItem("Our Services", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(new MenuItem("Feedback", "", "", "~/Pages/FeedbackList.aspx"));
            smoothmenu1.Items.Add(new MenuItem("About Us", "", "", "~/About.aspx"));
        }
        private void SystemAdminMenu()
        {
            smoothmenu1.Items.Clear();
            DefaultMenu();
        }
        private void SystemOpreatorMenu()
        {
            smoothmenu1.Items.Clear();
            DefaultMenu();
        }
        private void SocietySuperAdminMenu()
        {
            smoothmenu1.Items.Clear();
            smoothmenu1.Items.Add(new MenuItem("Home", "", "", "~/HsmpHomePage1.aspx"));
            smoothmenu1.Items.Add(new MenuItem("My Society", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            MenuItem mItemsSocietyAdmin = new MenuItem("Society Admin", "", "", "");
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Update Society Details", "", "", "~/Pages/SocietyManagementComm.aspx"));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Update Flat Details", "", "", "~/Pages/FlatOwnerRegister.aspx"));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Add Society Admin", "", "", "~/Pages/SocietyManagementComm.aspx"));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Publish Notice", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Reports", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(mItemsSocietyAdmin);

            smoothmenu1.Items.Add(new MenuItem("Our Services", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(new MenuItem("Feedback", "", "", "~/Pages/FeedbackList.aspx"));
            smoothmenu1.Items.Add(new MenuItem("About Us", "", "", "~/About.aspx"));
        }
        private void SocietyAdminMenu()
        {
            smoothmenu1.Items.Clear();
            smoothmenu1.Items.Add(new MenuItem("Home", "", "", "~/HsmpHomePage1.aspx"));
            smoothmenu1.Items.Add(new MenuItem("My Society", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            MenuItem mItemsSocietyAdmin = new MenuItem("Society Admin", "", "", "");
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Update Society Details", "", "", "~/Pages/SocietyManagementComm.aspx"));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Update Flat Details", "", "", "~/Pages/FlatOwnerRegister.aspx"));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Publish Notice", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Reports", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(mItemsSocietyAdmin);

            smoothmenu1.Items.Add(new MenuItem("Our Services", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(new MenuItem("Feedback", "", "", "~/Pages/FeedbackList.aspx"));
            smoothmenu1.Items.Add(new MenuItem("About Us", "", "", "~/About.aspx"));
        }
        private void SocietyOpreatorMenu()
        {
            smoothmenu1.Items.Clear();
            smoothmenu1.Items.Add(new MenuItem("Home", "", "", "~/HsmpHomePage1.aspx"));
            smoothmenu1.Items.Add(new MenuItem("My Society", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            MenuItem mItemsSocietyAdmin = new MenuItem("Opreator", "", "", "");
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Update Society Details", "", "", "~/Pages/SocietyManagementComm.aspx"));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Update Flat Details", "", "", "~/Pages/FlatOwnerRegister.aspx"));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Publish Notice", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Reports", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(mItemsSocietyAdmin);

            smoothmenu1.Items.Add(new MenuItem("Our Services", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(new MenuItem("Feedback", "", "", "~/Pages/FeedbackList.aspx"));
            smoothmenu1.Items.Add(new MenuItem("About Us", "", "", "~/About.aspx"));
        }
        private void BuilderMenu()
        {
            smoothmenu1.Items.Clear();
            DefaultMenu();
        }
        private void FlatOwnerMenu()
        {
            smoothmenu1.Items.Clear();
            smoothmenu1.Items.Add(new MenuItem("Home", "", "", "~/HsmpHomePage1.aspx"));
            smoothmenu1.Items.Add(new MenuItem("My Society", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            MenuItem mItemsSocietyAdmin = new MenuItem("Flat Owner", "", "", "");
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Update Profile", "", "", "~/Pages/FlatOwnerRegister.aspx"));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Update Flat Details", "", "", "~/Pages/FlatOwnerRegister.aspx"));
            mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Publish Notice", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            //mItemsSocietyAdmin.ChildItems.Add(new MenuItem("Reports", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(mItemsSocietyAdmin);

            smoothmenu1.Items.Add(new MenuItem("Our Services", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(new MenuItem("Feedback", "", "", "~/Pages/FeedbackList.aspx"));
            smoothmenu1.Items.Add(new MenuItem("About Us", "", "", "~/About.aspx"));
        }
        private void ResidentrMenu()
        {
            smoothmenu1.Items.Clear();
            DefaultMenu();
        }
        private void DefaultMenu()
        {
            smoothmenu1.Items.Clear();
            smoothmenu1.Items.Add(new MenuItem("Home", "", "", "~/HsmpHomePage1.aspx"));
            //MenuItem mItemsMasterData = new MenuItem("Master Data", "", "", "~/Pages/FlatListing.aspx");
            //mItemsMasterData.ChildItems.Add(new MenuItem("Society Master", "", "", "~/Pages/SocietyListing.aspx"));
            //mItemsMasterData.ChildItems.Add(new MenuItem("Flat Master", "", "", "~/Pages/FlatDetails.aspx"));
            //mItemsMasterData.ChildItems.Add(new MenuItem("Owner Master", "", "", "~/Pages/OwnerDetails.aspx"));
            //mItemsMasterData.ChildItems.Add(new MenuItem("Tenent Master", "", "", "~/Pages/TenentDetails.aspx"));
            //smoothmenu1.Items.Add(mItemsMasterData);
            //MenuItem mItems = new MenuItem("Products", "");
            //mItems.ChildItems.Add(new MenuItem("Feedback Service", "", "", "~/Pages/ComingSoon.aspx?PageHeadline=Feedback Service – Coming soon"));
            //smoothmenu1.Items.Add(mItems);
            smoothmenu1.Items.Add(new MenuItem("Our Services", "", "", "~/Pages/ComingSoon.aspx?PageHeadline="));
            smoothmenu1.Items.Add(new MenuItem("Feedback", "", "", "~/Pages/FeedbackList.aspx"));
            smoothmenu1.Items.Add(new MenuItem("About Us", "", "", "~/About.aspx"));
        }
        #endregion Private Methods

            }
}